package com.euq.mapper;

import com.euq.entity.Role;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface RoleMapper {
    @Select("select * from role")
    List<Role> listAll();
    @Delete("delete * from role")
    void delete(Long id);
    @Select("select * from role where id=#{id}")
    Role findById(Long id);
    @Select({
            "<script>",
            "SELECT * FROM user",
            "<where>",
            "  <if test='name != null and name != \"\"'>",
            "    AND name = #{name}",
            "  </if>",
            "  <if test='tips != null and tips != \"\"'>",
            "    AND tips = #{tips}",
            "  </if>",
            "</where>",
            "</script>"
    })
    List<Role> selectRoles(String name,String tips);
    @Select("select * from role where name=#{name} and tips=#{tips} and deptId=#{deptId}")
    Role check(String name, String tips, Long deptId);
    @Insert({"INSERT INTO role(create_by, create_time, modify_by, modify_time, deptId, name, num, pid, tips, version)",
            "VALUES (1,now(),1,now(), #{deptId}, #{name}, #{num}, #{pid}, #{tips}, 1)"
    })
    void insert(String name, String tips, Long deptId, Long pid, int num);
    @Update({"UPDATE role " +
            "SET create_by = 1, " +
            "create_time = now(), " +
            "modify_by = 1, " +
            "modify_time = now(), " +
            "deptId = #{deptId}, " +
            "name = #{name}, " +
            "num = #{num}, " +
            "pid = #{pid}, " +
            "tips = #{tips}, " +
            "version = 1 " +
            "WHERE id = #{id}"})
    void update(String name, String tips, Long deptId, Long pid, int num,Long id);
}
